﻿using System;
using DMS.Business.Utility;
using DMS.Business.Modules.Organization;

namespace DMS.Business.Modules.Configuation
{
    public class MemberConfig
    {
        #region 成员数据
        private SysConfig _Default = null;

        private string _ID = string.Empty;
        private string _Value = string.Empty;

        private string _MemberID = "";
        private ActorTypes _MemberType = ActorTypes.User;

        /// <summary>
        /// 标识
        /// </summary>
        public string ID
        {
            get
            {
                return this._ID;
            }
        }
        /// <summary>
        /// 显示标题
        /// </summary>
        public string Name
        {
            get
            {
                return this._Default.Name;
            }
        }
        /// <summary>
        /// 值
        /// </summary>
        public string Value
        {
            get
            {
                return this._Value;
            }
            set
            {
                this._Value = value;
            }
        }

        public string MemberID
        {
            get
            {
                return this._MemberID;
            }
        }
        public ActorTypes MemberType
        {
            get
            {
                return this._MemberType;
            }
        }

        public SysConfig Default
        {
            get
            {
                return this._Default;
            }
        }
        #endregion

        #region 构造函数
        public MemberConfig(Actor member, SysConfig defaultConfig)
            :this(member.ID, member.ActorType, defaultConfig)
        {
        }
        internal MemberConfig(string memberID, ActorTypes memberType, SysConfig defaultConfig)
        {
            this._MemberID = memberID;
            this._MemberType = memberType;

            this._Default = defaultConfig;
            this._ID = defaultConfig.ID;

            this._Value = defaultConfig.Value;
        }
        #endregion

        #region 成员方法
        public void Save()
        {
            MemberConfig config = ConfigHelper.GetMemberConfig(this.MemberID, this.ID);
            if (config == null)
            {
                ConfigHelper.AddMemberConfig(this.Default, this.Value, this.MemberID, this.MemberType);
            }
            else
            {
                ConfigHelper.UpdateMemberConfig(this);
            }
        }
        #endregion
    }
}
